package com.woniu.bank.service.impl;


import com.woniu.bank.dto.UserDTO;
import com.woniu.bank.entity.SysUser;
import com.woniu.bank.mapper.SysUserMapper;
import com.woniu.bank.service.SysUserService;
import com.woniu.bank.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：lgy
 * @description：TODO
 * @date ：2022/12/6 14:11
 */
@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    /**
     * 登录所需的账号密码验证
     * @param userDTO
     * @return
     */
    @Override
    public SysUser selectByTelAndPwd(UserDTO userDTO) {
        redisTemplate.delete("sysPermissions");
        return sysUserMapper.selectByTelAndPwd(userDTO.getTel(), userDTO.getPassword());
    }

    @Override
    public List<UserVO> selectAllUser(UserDTO userDTO) {
        return sysUserMapper.selectAllUser(userDTO);
    }

    @Override
    public int updateByPrimaryKeySelective(SysUser record) {
        return sysUserMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int insertSelective(SysUser record) {
        record.setPassword("123456");
        record.setStatus("1");
        record.setRealName("新人");
        record.setHeadImg("https://s1.ax1x.com/2022/12/10/zfAaiq.png");
        return sysUserMapper.insertSelective(record);
    }

    @Override
    public SysUser selectByTel(SysUser sysUser) {
        return sysUserMapper.selectByTel(sysUser);
    }
}
